<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_users', function (Blueprint $table) {
            $table->id();
            $table->string('account', 50)->default('')->unique()->comment('账号');
            $table->string('password', 255)->default('')->comment('密码');
            $table->string('name', 50)->default('')->comment('管理员名称');
            $table->string('email', 255)->default('')->comment('管理员邮箱');
            $table->string('phone', 11)->default('')->comment('管理员手机号');
            $table->integer('role_id')->default(0)->comment('角色id');
            $table->integer('group_id')->default(0)->comment('组织id');
            $table->tinyInteger('is_show')->default(1)->comment('是否展示:0=否,1=是');
            $table->integer('login_at')->default(0)->comment('最近登录时间');
            $table->integer('login_num')->default(0)->comment('登录次数');
            $table->string('uuid', 255)->default('')->comment('单点登录');
            $table->tinyInteger('status')->default(0)->comment('状态:1=正常,2=禁用');
            $table->tinyInteger('is_delete')->default(0)->comment('是否删除:1=删除,0=正常');
            $table->integer('created_at')->default(0)->comment('创建时间');
            $table->integer('updated_at')->default(0)->comment('修改时间');
        });
        DB::statement("ALTER TABLE `admin_users` comment '【后台】管理用户'");
        // 初始化管理员表
        DB::table('admin_users')->insert([
            'account' => 'admin_rat',
            'password' => Hash::make(md5('panda2022')),
            'name' => '系统管理员',
            'role_id' => 1,
            'is_show' => 0,
            'status' => 1,
            'created_at' => time(),
            'updated_at' => time()
        ]);
        DB::table('admin_users')->insert([
            'account' => 'admin',
            'password' => Hash::make(md5('123456')),
            'name' => '管理员',
            'role_id' => 2,
            'is_show' => 1,
            'status' => 1,
            'created_at' => time(),
            'updated_at' => time()
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
    }
};
